package edu.whu.tao.tag;

import edu.whu.tao.constant.CommonConstants;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xiaoleilu.hutool.util.CollectionUtil;
import com.xiaoleilu.hutool.util.StrUtil;



public abstract class SecureTag extends TagSupport {
	
	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;
	
	private static final Logger log = LoggerFactory.getLogger(SecureTag.class);

	protected String[] getRoles() {
		String strRoles = (String) pageContext.getSession().getAttribute(CommonConstants.ROLES_KEY);
		String[] hasRoles = null;
		if(strRoles==null){
			hasRoles = (String[])CollectionUtil.newArray(String.class, 0);
		}
		hasRoles = StrUtil.split(strRoles, ",");
		return hasRoles;
	}

	protected void verifyAttributes() throws JspException {
	}

	public int doStartTag() throws JspException {
		verifyAttributes();

		return onDoStartTag();
	}

	public abstract int onDoStartTag() throws JspException;
}
